const Koa = require('koa')
const static = require('koa-static')
const path = require('path')
const historyApiFallback = require('koa2-connect-history-api-fallback');
const response = require('./middlewares/response')
// const koaBetterBody = require('koa-better-body')
// const upload = require('./routes/upload')
// const body = require('./middlewares/body')
// const bodyParser = require('koa-bodyparser')
const app = new Koa()
const staticPath = './dist'
const router = require('./routes')
const ueditor = require('./routes/ueditor')
app.use(historyApiFallback({ whiteList: ['/api', '/ueditor'] }));
app.use(static(
  path.join(__dirname, staticPath)
))
app.use(response)
// app.use(body)
// app.use(koaBetterBody({
//       fields: 'body'
//     }))
// app.use(bodyParser())
// app.use(koaBetterBody({
//   fields: 'body'
// }))
// 引入路由分发
app.use(router.routes())
app.use(ueditor.routes())
// app.use(upload.routes())
app.listen(3000, () => {
  console.log('server is starting at port 3000')
})
